#include <stdio.h>

#include "paint.h"
#include "board.h"
#include "computer.h"
#include "mouse.h"
#include "tcp.h"

int main(int argc, char *argv[])
{
	int r, c, w;
	int fd;

	open_fb();
	show_board();
	open_mouse();

	init_tcp_client(argc, argv);
	fd = get_client_fd();

	while (1)
	{
		if ((w = step % 2 + 1) == 1)
		{
			receive_from(fd, &r, &c);
			show_piece(r, c, w);

			if (is_win(r, c))
				break;
		}
		else
		{
			if (mouse_input(&r, &c, w))
			{
				show_piece(r, c, w);
				send_to(fd, r, c);

				if (is_win(r, c))
					break;
			}
		}
		read_mouse();
	}

	printf("GAME OVER\n");

	close_mouse();
	close_fb();

	return 0;
}
